<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('月度评价任务台账列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">任务年月</label>
                <div class="layui-input-inline">
                    <input type="text" name="evaluationDate" placeholder="" class="layui-input" id="taskMonth">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                        lay-filter="monthEvaluation-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="monthEvaluation-table" lay-filter="monthEvaluation-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="monthEvaluation-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="viewrpa">
        <i class="layui-icon layui-icon-engine"></i>
        查看RPA指标同步状态
    </button>
    <button shiro:hasPermission="gen:monthEvaluation:add" class="pear-btn pear-btn-warming pear-btn-md"
            lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        生成评价任务
    </button>
    <!--    <button shiro:hasPermission="gen:monthEvaluation:remove" class="pear-btn pear-btn-danger pear-btn-md"-->
    <!--            lay-event="batchRemove">-->
    <!--        <i class="layui-icon layui-icon-delete"></i>-->
    <!--        删除-->
    <!--    </button>-->
</script>

<script type="text/html" id="monthEvaluation-bar">
    <!--    <button shiro:hasPermission="gen:monthEvaluation:edit" class="pear-btn pear-btn-primary pear-btn-sm"-->
    <!--            lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>-->
    <!--    </button>-->

    <!--    <button shiro:hasPermission="gen:monthEvaluation:remove" class="pear-btn pear-btn-danger pear-btn-sm"-->
    <!--            lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>-->
    <!--    </button>-->
    <button class="pear-btn pear-btn-warming pear-btn-sm"
            lay-event="findFillPlan">
        查看提报进度
    </button>
    <button class="pear-btn pear-btn-warming pear-btn-sm"
            lay-event="findAuditPlan">
        查看审核进度
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-sm"
            lay-event="findResult">
        查看实时结果
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-sm"
            lay-event="issueResult">
        发布最终结果
    </button>
</script>


<script type="text/html" id="monthEvaluation-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#taskMonth' //指定元素
            ,type: 'month'
        })

        var MODULE_PATH = rootPath + "/MonthEvaluationController/";
        var cols = [
            [
                {type: 'checkbox'},

                // {title: '主键id', field: 'id', align: 'center'},
                //
                // {title: '任务id', field: 'taskId', align: 'center'},

                {title: '任务名称', field: 'taskName', align: 'center'},

                {title: '任务年月', field: 'evaluationDate', align: 'center'},

                {
                    field: 'status', title: '发布状态', align: 'center', templet: function (res) {
                        if (res.status == '0') {
                            return '未发布';
                        } else if (res.status == '1') {
                            return '已发布';
                        }
                    }
                },

                {title: '创建时间', field: 'createTime', align: 'center'},

                // {title: '创建人员id', field: 'createUserId', align: 'center'},

                // {title: '创建人员', field: 'createUserName', align: 'center'},

                {title: '发布时间', field: 'issueTime', align: 'center'},
                //
                // {title: '上次更新时间', field: 'updateTime', align: 'center'},

                {title: '操作', toolbar: '#monthEvaluation-bar', align: 'center', width: 500}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#monthEvaluation-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#monthEvaluation-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }]
        });

        //table图标事件绑定
        table.on('tool(monthEvaluation-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else if (obj.event === 'findFillPlan') {
                window.findFillPlan(obj);
            } else if (obj.event === 'findAuditPlan') {
                window.findAuditPlan(obj);
            } else if (obj.event === 'findResult') {
                window.findResult(obj);
            } else if (obj.event === 'issueResult') {
                window.issueResult(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(monthEvaluation-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            } else if (obj.event === 'viewrpa') {
                window.viewrpa(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(monthEvaluation-query)', function (data) {
            table.reload('monthEvaluation-table', {where: data.field})
            return false;
        });

        //查看RPA指标同步状态
        window.viewrpa = function () {
            var index = layer.open({
                type: 2,
                title: 'RPA指标同步结果查询',
                shade: 0.1,
                // area: ['600px', '400px'],
                content: MODULE_PATH + 'viewrpa'
            });
            layer.full(index)
        }
        //添加
        window.add = function () {
            layer.open({
                type: 2,
                title: '新增任务',
                shade: 0.1,
                area: ['600px', '400px'],
                content: MODULE_PATH + 'add'
            });
        }
        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
        }
        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('monthEvaluation-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }
        //刷新按钮
        window.refresh = function () {
            table.reload('monthEvaluation-table');
        }

        //查看填报进度
        window.findFillPlan = function (obj) {
            console.log(obj.data['id'])
            var index = layer.open({
                type: 2,
                title: '查看填报进度--'+ obj.data['taskName'],
                shade: 0.1,
                content: MODULE_PATH + 'findFillPlan/' + obj.data['id']
            });
            layer.full(index);
        }

        //查看审核进度
        window.findAuditPlan = function (obj) {
            console.log(obj.data['id'])
            var index = layer.open({
                type: 2,
                title: '责任部门审核进度--'+ obj.data['taskName'],
                shade: 0.1,
                content: MODULE_PATH + 'findAuditPlan/' + obj.data['id']
            });
            layer.full(index);
        }

        //查看实时结果
        window.findResult = function (obj) {
            console.log(obj.data['id'])
            var index = layer.open({
                type: 2,
                title: '查看实时结果--'+ obj.data['taskName'],
                shade: 0.1,
                content: MODULE_PATH + 'findResult/' + obj.data['evaluationDate']
            });
            layer.full(index);
        }

        //发布结果
        window.issueResult = function (obj) {
            layer.confirm('结果发布后不可更改，确定发布结果么', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "issueResult/" + obj.data['id'],
                    dataType: 'json',
                    method: 'get',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000});
                            table.reload('monthEvaluation-table');
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }
    })
</script>
</html>